import {observable, action} from 'mobx';
import {BrowserHrm,Browser} from 'weaver-mobile-page';
import * as API from '../api/smsApi.js';

export default class smsStore {
  @observable browserHrm = new BrowserHrm.Store({ route: '/sendSms', id: 'receivehrm' });
  @observable browserHrmValue = [];
  @observable browserClient = new Browser.Store({ route: '/sendSms', id: 'clienthrm' });
  @observable browserClientValue = [];
  @observable hrmids = [];
  @observable crmids = [];
  @observable telArr = '';
  @observable smsContent = '';
  @observable successflag = false;
  @observable loading = true;
  @observable canSend = true; // 发送权限判断
  @observable isGov = true; // 客户联系人显隐
  @observable sendCrm = [];
  @observable showCusSign = true;
  @observable showReply = true; //
  @observable listArr = []; //
  
  @action
  setParams = (params={}) => {
    Object.keys(params).forEach(key => {
      this[key] = params[key];
    })
  }
  sendSms = (params, callback) => {
    API.sendSms(params).then(res => {
      this.successflag = res.successflag;
      if(res.successflag) {
        this.setParams({browserHrmValue: [],browserClientValue: [],listArr: [],smsContent:'',hrmids: [],crmids: [],});
      }
      typeof(callback) === 'function' && callback()
    });
  }
  getBaseData = (params) => {
    API.getBaseData(params).then(res => {
      this.loading = false;
      this.canSend = res.canSend;
      this.isGov = res.isGov;
      this.sendCrm = res.sendCrm;
      this.browserHrmValue = res.sendHrm;
      this.smsContent = res.msg;
      res.sendHrm && res.sendHrm.map(res => {
        this.hrmids.push(res.id); // 初始化
        return '';
      })
      this.browserClientValue = res.sendCrm;
      res.sendCrm && res.sendCrm.map(res => {
        this.crmids.push(res.id); // 初始化
        return '';
      })
      this.showCusSign = res.showCusSign;
      this.showReply = res.showReply;
    });
  }
}